#include "DataManage.h"
#include "ConstClass.h"
#include "PlayerInfo.h"
#include "PlayLayer.h"
#include "ComManage.h"
#include "CardLayer.h"

DataManage::DataManage()
{
}


DataManage::~DataManage()
{
}

void DataManage::initialPlayers()
{
	if (ConstClass::COM_GAME)
	{
		ComManage::initialPlayers();	
	}
	else
	{

	}
	
}

void DataManage::shuffle()
{
	if (ConstClass::COM_GAME)
	{
		ComManage::shuffle();
	}
}

void DataManage::sendNewRoundCard()
{
	if (ConstClass::COM_GAME)
	{
		ComManage::sendNewRoundCard();
	}
}

void DataManage::getCard()
{
	if (ConstClass::COM_GAME)
	{
		ConstClass::NEWCARD_ID = ComManage::getCard();
		getCardHandler();
	}
	else
	{

	}
}

void DataManage::getCardHandler()
{
	CardLayer::playCardHandler();
}

void DataManage::playCard(int cardID, int cardID2)
{
	if (ConstClass::COM_GAME)
	{
		ComManage::playCard(cardID);
	}
	else
	{

	}
}

void DataManage::getResult()
{
	if (ConstClass::COM_GAME)
	{
		int* result = ComManage::getComResult();
		int cardID = *result;

		if (cardID < 15)
		{
			getResultHandler(cardID);
		}
		else
		{
			result++;
			int cardID2 = *result;
			getResultHandler(cardID, cardID2);
		}
	}
	else
	{

	}
}

void DataManage::getResultHandler(int cardID)
{
	PlayLayer::thisLayer->pauseRound();
	PlayLayer::thisLayer->playCard(cardID);
}

void DataManage::getResultHandler(int colorCardID, int cardID)
{
	PlayLayer::thisLayer->pauseRound();
	PlayLayer::thisLayer->playCard(colorCardID, cardID);
}

void DataManage::getWinner(int winnerT)
{
	if (ConstClass::COM_GAME)
	{
		ComManage::getWinnerPID(winnerT);
		getWinnerHandler();
	}
	else
	{

	}
}

void DataManage::getWinnerHandler()
{
	PlayLayer::thisLayer->gameOver();
}